﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class MonAnDAO
    {
        public static bool Insert(MonAnDTO ma)
        {
            bool result = false;

            string strSQLEmployee = "Insert into MonAn(TenMonAn,LoaiMon,DonGia) values (@TenMonAn,@LoaiMon,@DonGia)";

            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TenMonAn", ma.TenMonAn));
                sqlParams.Add(new SqlParameter("@LoaiMon", ma.LoaiMon));
                sqlParams.Add(new SqlParameter("@DonGia", ma.DonGia));
                // Call execute none query

                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);//.ExecuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        public static bool Update(MonAnDTO ma)
        {
            bool result = false;

            string strSQLEmployee = "Update MonAn set TenMonAn=@TenMonAn,LoaiMon=@LoaiMon,DonGia=@DonGia " +
                "Where MaMonAn=@MaMonAn";

            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaMonAn", ma.MaMonAn));
                sqlParams.Add(new SqlParameter("@TenMonAn", ma.TenMonAn));
                sqlParams.Add(new SqlParameter("@LoaiMon", ma.LoaiMon));
                sqlParams.Add(new SqlParameter("@DonGia", ma.DonGia));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        public static bool Delete(int MaMA)
        {
            bool result = false;
            string strSQLEmployee = "DELETE FROM MonAn WHERE MaMonAn=@MaMonAn";
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaMonAn", MaMA));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }

        public static DataTable SelectAll()
        {
            String strSql = "Select MaMonAn, TenMonAn, MaLoai, TenLoai, DonGia from MonAn, LoaiMonAn " +
                "Where MonAn.LoaiMon = LoaiMonAn.MaLoai";

            try
            {
                DataTable dt = SqlDataAccessHelper.ExcuteQuery(strSql);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
